'''
@Descripttion: 
@version: 
@encoding: utf-8
@Author: qiurongcan
Date: 2025-08-29 14:36:58
LastEditTime: 2025-08-29 14:50:14
'''
# 删除链表倒数n个节点

class ListNode:

    def __init__(self, val, next=None):
        self.val = val
        self.next = next

class Solution:

    def removeNthFromEnd(self, head, n):
        # 创建一个哨兵节点
        left = right = dummy = ListNode(next=head)

        for _ in range(n):
            # 右指针先走n步
            right = right.next
        while right.next:
            left = left.next
            right = right.next
        
        left.next = left.next.next

        return dummy.next



    






